  #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
  CBUFFER_START(UnityPerMaterial)
    half4 _BaseColor;
    half4 _BaseMap_ST;
    half4 _BumpMap_ST;
    half _BumpScale;
 
    //half4 _EmissionColor;
    half4 _BumpSpeed;
    half _Cutoff;
    half _Smoothness;
    half _Metallic;
    
    half _FresnelPower;
    half _ReflectDistance;
 
    half _ReflectBumpPower;
 
    half _SpecularMaxLimit;
    half _CustomCubeTexBrightness;
    half _AlphaCtrl;
 
    //#endif
CBUFFER_END
TEXTURE2D(_BaseMap);SAMPLER(sampler_BaseMap);
 
TEXTURE2D(_BumpMap);        SAMPLER(sampler_BumpMap);
TEXTURE2D(_FlowMap);        SAMPLER(sampler_FlowMap);
TEXTURE2D(_CameraOpaqueTexture);
SAMPLER(sampler_CameraOpaqueTexture);
TEXTURE2D(_CameraDepthTexture);
SAMPLER(sampler_CameraDepthTexture);


half Alpha(half albedoAlpha, half4 color, half cutoff)
{
#if !defined(_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A) && !defined(_GLOSSINESS_FROM_BASE_ALPHA)
    half alpha = albedoAlpha * color.a;
#else
    half alpha = color.a;
#endif

#if defined(_ALPHATEST_ON)
    clip(alpha - cutoff);
#endif

    return alpha;
}
half4 SampleAlbedoAlpha(float2 uv, TEXTURE2D_PARAM(albedoAlphaMap, sampler_albedoAlphaMap))
{
    return half4(SAMPLE_TEXTURE2D(albedoAlphaMap, sampler_albedoAlphaMap, uv));
}
 
 #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
 #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
 #include "lch_pbr.hlsl"


 #if defined(  ANISOTROPIC_FLOWMAP)
    #define BITANGENT_SPACE  
    #define FLOWMAP   
#endif








#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl"


 

half3 SampleNormal(float2 uv, TEXTURE2D_PARAM(bumpMap, sampler_bumpMap), half scale = half(1.0))
{
#ifdef _NORMALMAP
    half4 n = SAMPLE_TEXTURE2D(bumpMap, sampler_bumpMap, uv);
    /*#if BUMP_SCALE_NOT_SUPPORTED
        return UnpackNormal(n);
    #else*/
        return UnpackNormalScale(n, scale);
   // #endif
#else
    return half3(0.0h, 0.0h, 1.0h);
#endif
}
          
        
half3 GetNormalST(float2 uv,float invNoV)
{
    #ifdef _NORMALMAP
    float scale = _BumpScale;

    scale = _BumpScale* lerp(1 ,_ReflectBumpPower,invNoV );
    return SampleNormal(uv, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap), scale);
    #else
    return  half3(0,0,1);
    #endif
}

 

float3 blend_rnm_unpacked(float3 n1, float3 n2)
{
    float3 t = n1.xyz + float3( 0,  0, 1);
    float3 u = n2.xyz * float3(-1, -1, 1);
    float3 r = (t/t.z)*dot(t, u) - u;
    return r;
}

#if defined( ANISOTROPIC_ON )||defined(  ANISOTROPIC_FLOWMAP)
    #define BITANGENT_SPACE   
#endif
#if defined(  ANISOTROPIC_FLOWMAP)
    #define BITANGENT_SPACE  
    #define FLOWMAP   
#endif
inline void InitializeLchSurfaceData(float2 uv, out LchSurfaceData outSurfaceData,float invNoV)
{

      outSurfaceData. albedo= 0.0;
 
     outSurfaceData.   metallic= 0.0;
     outSurfaceData.   smoothness= 0.0;
     outSurfaceData.  normalTS= 0.0;
     outSurfaceData.  emission= 0.0;
     outSurfaceData.   occlusion= 0.0;
     outSurfaceData.   alpha= 0.0;  

    
    
   
    

    half4 albedoAlpha = 1.0; 
    outSurfaceData.alpha = _BaseColor.a;

      

 
    outSurfaceData.albedo = albedoAlpha.rgb * _BaseColor.rgb;
    outSurfaceData.metallic =_Metallic;
    outSurfaceData.smoothness = _Smoothness;
    outSurfaceData.normalTS = blend_rnm_unpacked(GetNormalST(uv+_BumpSpeed.xy*_Time.y,invNoV),GetNormalST(uv+_BumpSpeed.zw*_Time.y,invNoV)   );
    outSurfaceData.occlusion =  1.0;
    outSurfaceData.emission = 0.0;



    #ifdef _SSS
    outSurfaceData.sssColor = _SssColor;
 
    outSurfaceData.sssAmb =_SssAmb;
    
 
    #endif


    #if defined(ANISOTROPIC_FLOWMAP)
        outSurfaceData.anisoGlass = _AnisoGlass.rgb ;
        outSurfaceData.primaryShift = _PrimaryShift;
 
        outSurfaceData.anisoPower = _AnisoPower;
        half4 n = SAMPLE_TEXTURE2D(_FlowMap, sampler_FlowMap, uv);
        outSurfaceData.anisoDirTS =  n.rgb*2-1;
 
    #elif defined(ANISOTROPIC_ON)  
        outSurfaceData.anisoGlass = _AnisoGlass.rgb ;
        outSurfaceData.primaryShift = _PrimaryShift;
 
        outSurfaceData.anisoPower = _AnisoPower;
        outSurfaceData.anisoDirTS = half3(0.0,1.0,0.0);

    #else
        outSurfaceData.anisoGlass = 0.0;
        outSurfaceData.primaryShift = 0.0;
        outSurfaceData.anisoPower = 0.0;
        outSurfaceData.anisoDirTS = half3(0.0,1.0,0.0);
    #endif

        outSurfaceData.backLight = 0.0;
    outSurfaceData.maxLimit = _SpecularMaxLimit;
 
} 

